package com.hfzy.ihk.facade.aliyuncall.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/28.
 *
 * @author wws
 */
public enum MainCallTypeEnum {


    MAIN_CALL_PHONE_IS_CUSTOMER("主叫号码是客户号码",0),
    MAIN_CALL_PHONE_IS_SALES("主叫号码是经纪号码",1);


    /** 描述 */
    private String desc;
    /** 枚举值 */
    private int value;

    private MainCallTypeEnum(String desc, int value) {
        this.desc = desc;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    private static Map<String, MainCallTypeEnum> descMap = new HashMap<String, MainCallTypeEnum>();

    private static Map<String, MainCallTypeEnum> map = new HashMap<String, MainCallTypeEnum>();

    private static Map<String, String> keyMap = new HashMap<String, String>();

    static {
        for (MainCallTypeEnum value : MainCallTypeEnum.values())
            keyMap.put(value.getValue() + "", value.getDesc());
    }

    static {
        for (MainCallTypeEnum value : MainCallTypeEnum.values())
            descMap.put(value.getDesc(), value);
    }

    static {
        for (MainCallTypeEnum value : MainCallTypeEnum.values()) {
            map.put(value.getValue() + "", value);
        }
    }

    public static MainCallTypeEnum getEnum(int value){
        MainCallTypeEnum resultEnum = null;
        MainCallTypeEnum[] enumAry = MainCallTypeEnum.values();
        for(int i = 0;i<enumAry.length;i++){
            if(enumAry[i].getValue() == value){
                resultEnum = enumAry[i];
                break;
            }
        }
        return resultEnum;
    }

    public static Map<String, Map<String, Object>> toMap() {
        MainCallTypeEnum[] ary = MainCallTypeEnum.values();
        Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();
        for (int num = 0; num < ary.length; num++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String key = String.valueOf(getEnum(ary[num].getValue()));
            map.put("value", String.valueOf(ary[num].getValue()));
            map.put("desc", ary[num].getDesc());
            enumMap.put(key, map);
        }
        return enumMap;
    }


    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List toList(){
        MainCallTypeEnum[] ary = MainCallTypeEnum.values();
        List list = new ArrayList();
        for(int i=0;i<ary.length;i++){
            Map<String,String> map = new HashMap<String,String>();
            map.put("value",String.valueOf(ary[i].getValue()));
            map.put("desc", ary[i].getDesc());
            list.add(map);
        }
        return list;
    }

    public static MainCallTypeEnum fromStr(String name) {
        MainCallTypeEnum ret = map.get(name);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const "
                    + MainCallTypeEnum.class + "." + name);
    }

    public static MainCallTypeEnum fromDesc(String desc) {
        MainCallTypeEnum ret = descMap.get(desc);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const " + MainCallTypeEnum.class
                    + "." + desc);
    }

    public static String fromKey(String key) {
        String ret = keyMap.get(key);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const " + MainCallTypeEnum.class
                    + "." + key);
    }
}
